@extends('layouts.home.layout')

@section('content')
    @include('layouts.home._nav')

    <div class="validation main">
        <div class="validation_title">
            <h2>欢迎注册</h2>
        </div>
        <form action="{{url('user/register')}}" method="post" name="registerForm" id="registerForm">

            <div class="yzbox">
                <p>姓名</p>
                <input  placeholder="" name="name" class="zc_input name"/>
            </div>
            <span class="zhushi nametip">请提交姓名信息</span>
            <div class="yzbox">
                <p>性别</p>
                <div class="radiobox" style="border:none;">
                    <input type="radio" name="sex" value="1"  class="xianjin"/><p>男</p>
                    <input type="radio" name="sex" value="0" class="chuxuka"/><p>女</p>
                </div>
            </div>
            <div class="yzbox">
                <p>手机号码</p>
                <input  placeholder="" name="mobile" class="zc_input mobile"/>
            </div>
            <span class="zhushi">请提交正确的手机号码（由11位数字组成）</span>
            <div class="yzbox">
                <p>短信验证码</p>
                <div class="yanzhengma">
                    <input  placeholder="" name="code" class="code"/>
                    <button type="button" class="checkcell">获取验证码</button>
                </div>
            </div>
            <span class="zhushi codetip">请提交正确的手机号码（由11位数字组成）</span>
            <div class="yzbox">
                <p>设置密码</p>
                <input  placeholder="" type="password" name="password" class="zc_input password"/>
            </div>
            <span class="zhushi passwordtip">密码由6-20位的半角数字或字母字符组成</span>
            <div class="yzbox">
                <p>确认密码</p>
                <input  placeholder="" type="password" name="surepassword" class="zc_input surepassword"/>
            </div>
            <span class="zhushi surepassword">两次密码不一致</span>

            <div class="yz_p"><input type="checkbox" name="isagree" class="isagree"><p>我已阅读并同意<a href="http://www.51finace.com/main/serviceterms">《泛兰士服务条款》</a></p></div>

            <button class="nextbtn subForm" style="margin-top:30px;" type="text" disabled="disabled" >确认</button>

            <p class="dl_p">已有账号，去<a href="#" class="big-link" data-reveal-id="myModal" data-animation="none">登录</a></p>
        </form>
    </div>
@endsection
@section('js')
    <script>
        var smsUrl = "{{url('sms/send')}}";
        $(function () {
            $(".zhushi").hide();
            $(".mobile").blur(function () {
                var mobile=$('.mobile').val();

                var myreg = /^(((13[0-9]{1})|(17[0-9]{1})|(15[0-9]{1})|(18[0-9]{1}))+\d{8})$/;
                if (!myreg.test(mobile)) {
                    layer.msg('请输入有效的手机号码！');
                    return false;
                }

                var uri="{{url('user/ishavemobile')}}";
                $.post(uri,{mobile:mobile},function(result){
                    if(result.code=='0001'){
                        layer.msg(result.message);
                    }
                });
            });
            //同意
            $('.isagree').change(function(){
                if($('.isagree').is(':checked')==true){
                    $('.subForm').attr('disabled',false)
                }else{
                    $('.subForm').attr('disabled',true)
                }
            });

            $(document).ready(function () {
                var options = {
                    success: function (data) {
                        console.log(data);
                        layer.msg(data.message);
                        $(".subForm").attr('disabled',false);
                        if(data.code=='0000'){
                            setTimeout(function(){
                                window.location.href="{{url('main/index')}}"
                            },3000);
                        }
                    }
                };
                $(".subForm").click(function () {
                    var fm=document.forms['registerForm'];// HTML DOM 通过form 元素的name值获取
                    //
                    console.log(fm.name.value);
                    console.log(fm.mobile.value);
                    console.log(fm.sex.value);
                    console.log(fm.code.value);
                    console.log(fm.password.value);
                    if(fm.name.value==''){
                        layer.msg('请填写姓名');
                        return false;
                    }
                    if(fm.sex.value==''){
                        layer.msg('请选择性别');
                        return false;
                    }
                    var myreg = /^(((13[0-9]{1})|(17[0-9]{1})|(15[0-9]{1})|(18[0-9]{1}))+\d{8})$/;
                    if (!myreg.test(fm.mobile.value)) {
                        layer.msg('请输入有效的手机号码！');
                        return false;
                    }
                    if(fm.code.value==''){
                        layer.msg('请填写验证码');
                        return false;
                    }
                    if(fm.password.value==''){
                        layer.msg('请填写密码');
                        return false;
                    }
                    if(fm.password.value!=fm.surepassword.value){
                        layer.msg('两次密码填写不一致');
                        return false;
                    }

                    $(".subForm").attr('disabled',true);//禁用按钮
                    $("#registerForm").ajaxSubmit(options);
                });
            });
        })
    </script>
    <script src="/home/js/sendcode.js"></script>
@endsection